package com.itheima02.controller;

import com.itheima02.domain.Student;
import com.itheima02.service.StudentService;
import com.itheima02.service.StudentServiceDemo;
import org.junit.Test;

import java.util.Date;
import java.util.List;

public class StudentController {
    StudentService studentService = new StudentServiceDemo();

    // 查询所有
    @Test
    public void findAll(){
        List<Student> list = studentService.findAll();
        for (Student student : list) {
            System.out.println(student);
        }
    }

    // 根据学号查询
    @Test
    public void findByid(){
        Student stu = studentService.findByid(1);
        System.out.println(stu);
    }

    // 新增
    @Test
    public void insert(){
        Student stu = new Student(5, "周七", 23, new Date());
        int i = studentService.insert(stu);
        if (i != 0){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }

    // 修改
    @Test
    public void update(){
        Student stu = new Student(5, "周七", 23, new Date());
        int i = studentService.update(stu);
        if (i != 0){
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }
    }

    // 删除
    @Test
    public void delete(){
        int i = studentService.delete(5);
        if (i != 0){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }
}
